<template>
  <div class="box">
    <table-search
      slot="searchbar"
      v-model="searchData"
      :columns="searchOptions"
      @search="handleSearch"
    >
      <!-- <template slot="button">
        <a-button @click="handleExport" icon="download" style="color:#606266" slot="button" type="link">
          导出
        </a-button>|
        <a-button @click="handleAdd" icon="plus" style="color:#606266" slot="button" type="link">
          添加
        </a-button>
      </template> -->
    </table-search>
    <div class="table-box">
      <a-table
        :columns="columns"
        :data-source="data"
        size="middle"
        :scroll="{ x: 480 }"
        :pagination="false"
      >
        <template slot="index" slot-scope="scope">{{ scope.key }}</template>
        <template slot-scope="scope" slot="action">
          <a-button
            style="color: #2a5ee3"
            type="link"
            @click="handleMaintain(scope)"
            size="small"
          >
            维护
          </a-button>
        </template>
      </a-table>
      <div class="pagination-box">
        <a-pagination
          show-quick-jumper
          @change="handleChange"
          :show-total="(total) => `共 ${total} 条`"
          :defaultCurrent="pagination.current"
          :pageSize="pagination.pageSize"
          :total="pagination.total"
          :hideOnSinglePage="true"
        />
      </div>
    </div>
    <a-modal :visible="visible" width="400px">
      <template slot="title">
        <span>商品维护</span>
      </template>
      <template slot="closeIcon">
        <div style="width: 100%; height: 100%" @click="handleCancel">
          <a-icon type="close" />
        </div>
      </template>
      <template slot="footer">
        <div style="text-align: center">
          <a-button
            style="margin: 0 25px"
            key="back"
            type="danger"
            ghost
            @click="handleCancel"
          >
            取消
          </a-button>
          <a-button
            style="margin: 0 25px"
            key="submit"
            type="primary"
            :loading="confirmLoading"
            @click="handleOk"
          >
            确定
          </a-button>
        </div>
      </template>
      <a-form-model
        :model="form"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 14 }"
      >
        <a-form-model-item label="分类名称：" style="margin: 0 0 24px">
          <a-input
            v-model="form.supermarketName"
            placeholder="请输入分类名称"
          />
        </a-form-model-item>
        <a-form-model-item label="一级分类：" style="margin: 0 0 24px">
          <a-select
            v-model="form.name"
            show-search
            placeholder="请选择一级分类"
          >
            <a-select-option
              v-for="(opt, idx) in options"
              :key="idx"
              :value="opt.value"
            >
              {{ opt.label }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="二级分类：" style="margin: 0 0 24px">
          <a-select
            v-model="form.name"
            show-search
            placeholder="请选择二级分类"
          >
            <a-select-option
              v-for="(opt, idx) in options"
              :key="idx"
              :value="opt.value"
            >
              {{ opt.label }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="三级分类：" style="margin: 0 0 24px">
          <a-select
            v-model="form.name"
            show-search
            placeholder="请选择三级分类"
          >
            <a-select-option
              v-for="(opt, idx) in options"
              :key="idx"
              :value="opt.value"
            >
              {{ opt.label }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </div>
</template>

<script>
import columns from "./colums";
export default {
  data() {
    return {
      visible: false,
      confirmLoading: false,
      columns,
      data: [
        {
          key: "1",
          Level3: "其他日用杂品",
          Level2: "日用杂品",
          Level1: "日用杂品",
        },
        {
          key: "2",
          Level3: "其他日用杂品",
          Level2: "日用杂品",
          Level1: "日用杂品",
        },
      ],
      pagination: {
        total: 50,
        current: 1,
        pageSize: 10,
      },
      searchData: {},
      searchOptions: [
        {
          type: "text",
          label: "分类名称",
          prop: "Level2",
        },
        {
          type: "text",
          label: "上级分类名称",
          prop: "Level1",
        },
      ],
      options: [
        {
          value: "1",
          label: "none",
        },
      ],
      form: {},
    };
  },
  methods: {
    handleSearch(val) {
      console.log(val, "查询");
    },
    // handleEdit(val) {
    //   console.log(val,'编辑')
    // },
    // handleDelete(val) {
    //   console.log(val,'删除')
    // },
    handleMaintain(val) {
      this.visible = true;
      console.log(val, "维护");
    },
    handleChange(page, pageSize) {
      console.log(page, pageSize, "分页");
    },
    // handleExport() {
    //   console.log('导出')
    // },
    // handleAdd() {
    //   console.log('添加')
    // }
    handleCancel() {
      //取消
      this.visible = false;
    },
    handleOk() {
      //确定
      this.confirmLoading = true;
      setTimeout(() => {
        this.visible = false;
        this.confirmLoading = false;
      }, 2000);
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  .table-box {
    padding-top: 30px;
  }
  .pagination-box {
    text-align: right;
    // position: absolute;
    // bottom: 40px;
    // right: 16px;
    padding-top: 40px;
    .ant-pagination {
      display: inline-block;
    }
  }
}
</style>
